package test.juc;

/**
 * Created by shuoGG on 2018/10/25
 */
public class MainJuc {
    public static void main(String[] args) {
        new MainJuc().run();
    }

    private AsyncToSync juc = new AsyncToSync();

    private void run() {
        sendRequest(1);
        ack(1);
        sendRequest(2);
        ack(2);
        sendRequest(3);
        ack(3);
    }

    private void sendRequest(int sid) {
        new Thread(() -> {
            try {
                juc.sendRequestSingle(sid);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }

    private void ack(int sid) {
        new Thread(() -> {
            juc.sleep(2);
            juc.recAckSingle(sid);
        }).start();
    }
}
